package luogu;

import java.util.Scanner;

public class P1563 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        String[][] arr = new String[n][2];
        int[][] aaa = new int[m][2];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 2; j++) {
                arr[i][j] = sc.next();
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 2; j++) {
                aaa[i][j] = sc.nextInt();
            }
        }
        int res = 0;
        for (int i = 0; i < m; i++) {
            if (aaa[i][0] == 1){
                if (Integer.parseInt(arr[res][0]) == 0){
                    if (res + aaa[i][1] >= n){
                        res = res - n + aaa[i][1];
                    }else {
                        res = res + aaa[i][1];
                    }
                    continue;
                }
                if (Integer.parseInt(arr[res][0]) == 1){
                    if (res - aaa[i][1] < 0){
                        res = res + n - aaa[i][1];
                    }else {
                        res = res - aaa[i][1];
                    }
                    continue;
                }
            }
            if (aaa[i][0] == 0){
                if (Integer.parseInt(arr[res][0]) == 0){
                    if (res - aaa[i][1] < 0){
                        res = res + n - aaa[i][1];
                    }else {
                        res = res - aaa[i][1];
                    }
                    continue;
                }
                if (Integer.parseInt(arr[res][0]) == 1){
                    if (res + aaa[i][1] >= n){
                        res = res - n + aaa[i][1];
                    }else {
                        res = res + aaa[i][1];
                    }
                }
            }
        }
        System.out.println(arr[res][1]);
    }
}
